package com.pxmeta.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.dynamic.entity.dto.DynamicDTO;
import com.pxmeta.dynamic.service.IDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dynamic")
@Api(value = "动态管理",tags = "动态管理")
@RequiredArgsConstructor
@CrossOrigin
public class DynamicController {

    private final IDynamicService dynamicService;

    @GetMapping("/getList")
    @ApiOperation(value = "获取动态列表")
    public AjaxResult<List<DynamicDTO>> getList(@RequestParam Integer page,
                                       @RequestParam Integer size,
                                       @RequestParam(required = false) Integer status){
        //处理前端传参问题
        if (null != status && status == -10){
            status = null;
        }
        IPage<DynamicDTO> result = dynamicService.getList( page,size,status);
        return AjaxResult.successPage(result.getRecords(),result.getTotal());
    }


    @DeleteMapping("/deleteById/{id}")
    @ApiOperation(value = "删除动态")
    public AjaxResult deleteById(@PathVariable Long id){
        dynamicService.deleteDynamic(id);
        return AjaxResult.success();
    }

    @DeleteMapping("/realDeleteById/{id}")
    @ApiOperation(value = "彻底删除动态")
    public AjaxResult realDeleteById(@PathVariable Long id){
        dynamicService.realDeleteDynamic(id);
        return AjaxResult.success();
    }
}
